package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.ShoppingCart;
import com.sky.enumeration.OperationType;
import com.sky.service.impl.ShoppingCartServiceImpl;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 杨振华
 * @since 2023/7/23
 */
@Mapper
public interface ShoppingCartMapper {

    /**
     * 条件查询
     *
     * @param shoppingCart 购物车
     * @return {@link List}<{@link ShoppingCart}>
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);


    /**
     * 更新购物车数量
     *
     * @param shoppingCart 购物车
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateCartNumberById(ShoppingCart shoppingCart);

    /**
     * 插入
     *
     * @param shoppingCart 购物车
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 按用户id删除
     *
     * @param userId 用户id
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteByUserId(Long userId);

    /**
     * 批量加入购物车，再来一单
     *
     * @param shoppingCartList 购物车列表
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
